﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Battle
{
    public class ActivityBattleOver : IBattleOver
    {
        public BattleType GetBattleType()
        {
            return BattleType.ACTIVITY;
        }

        bool localResult;
        bool remoteResult;

        OnBattleResult onResult = null;

        public ActivityBattleOver(OnBattleResult onResult)
        {
            this.onResult = onResult;
        }


        public void Excute()
        {
            localResult = BattleManager.Instance.battleViewCtrl.winCamp == BattleCamp.Attacker;
            remoteResult = false;
            AskActiviryFightResult();
        }

        void AskActiviryFightResult()
        {
            ProtoBuf.Message.CSDailyCopyFightEnd msg = new ProtoBuf.Message.CSDailyCopyFightEnd();
            msg.optRecord = BattleNetOver.ParseOptRecord();
            msg.isWin = localResult ? 1:0;
            msg.ChapterId = StaticData.curBattleData.chapterId;
            msg.fightId = StaticData.curBattleData.fightId;
            NetAPI.SendHttp(ProtoBuf.Message.OpDefine.CSDailyCopyFightEnd, msg, (pack, bSuccess) =>
            {
                if (bSuccess)
                {
                    ProtoBuf.Message.SCDailyCopyFightEnd _msg = pack.kBody as ProtoBuf.Message.SCDailyCopyFightEnd;
                    remoteResult = _msg.isWin > 0 ? true : false;
                    StaticData.lastBattleEndMsg = _msg;
                    StaticData.isLastBattleWin = remoteResult;
                    End();
                }
            });
        }

        public void End()
        {
            if (onResult != null)
            {
                onResult(remoteResult);
            }
        }
    }
}
